
namespace Core.Features
{
    using System;
    using System.Linq;
    using Base;
    using Contracts.Enums;
    using Contracts.Interfaces;
    using Resources;

    
    public sealed class LockingRange<T> : FeatureBase<object>
    {
        public LockingRange(){}

        public LockingRange(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Locking range"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup{ get { return FeatureGroupsEnum.TargetingEquipment; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.LockingRange; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_meters; } }

        /// <summary>
        /// Determines if the feature value is rounded
        /// </summary>
        public override bool IsRounded
        {
            get { return false; }
        }

        /// <summary>
        /// Calculate the modified feature value
        /// </summary>
        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (agent == null || robot == null) return;

            // extensions
            double extensionBonus = agent.Extensions.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType);
            // SensorAmplifiers modules
            double moduleBonus = robot.Modules.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType, ModuleGroupsEnum.SensorAmplifiers);

            double temp = (double) Value * (1 + extensionBonus) * (1 + moduleBonus);

            // nexus Bonus
            double nexusBonus = robot.Modules.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType, ModuleGroupsEnum.NexusModuleFarlock);
            double nexusSkillBonus = agent.Extensions.SumModifiersValues(FeatureTypesEnum.Module, this.FeatureType);

            double nexusTotalBonus = 0;

            if (nexusBonus != 0)

                nexusTotalBonus = nexusBonus + (((1 + nexusBonus) * nexusSkillBonus) / 100);

            temp = temp * (1 + nexusTotalBonus);

            ModifiedValue = IsRounded
                ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                : Math.Round(temp, 2);
        }
    }
}